local xiejue = fk.CreateSkill{
    name = "SP_heg__xiejue",
    tags = { Skill.Limited, Skill.MainPlace },
}

Fk:loadTranslationTable{
    ["SP_heg__xiejue"] = "薤决",
    [":SP_heg__xiejue"] = "主将技，限定技，此武将牌上的单独阴阳鱼个数-1。当一名与你势力不同的角色死亡后，你可以增加1点体力上限并回复1点体力，且你的攻击范围+1，"..
    "然后你选择一名与你势力相同的其他角色<a href='heg_swap_deputy'>交换副将</a>。",

    ["@@heg__xiejue"] = "薤决攻击范围",
    ["#SP_heg__xiejue-choose"] = "薤决：选择一名与你势力相同的其他角色交换副将",

    ["$SP_heg__xiejue1"] = "怯战者立斩不赦，尔等勿忘吾剑之利！",
    ["$SP_heg__xiejue2"] = "人生百年，死国可乎！",
}

local H = require "packages.ol_hegemony.util"

xiejue:addEffect(fk.Deathed, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(xiejue.name) and player:usedSkillTimes(xiejue.name, Player.HistoryGame) == 0 
    and H.compareKingdomWith(data.damage.to, player, true)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, 1)
    if not player.dead and player:isWounded() then
      room:recover{
        who = player,
        num = 1,
        recoverBy = player,
        skillName = xiejue.name,
      }
    end
    room:setPlayerMark(player, "@@heg__xiejue", 1)
    local targets = table.filter(room:getOtherPlayers(player), function(p) return H.compareKingdomWith(p, player) 
    and not p.deputyGeneral:startsWith("blank_") end)
    if #targets == 0 then return end
    local to = room:askToChoosePlayers(player,{
      targets = targets,
      min_num = 1,
      max_num = 1,
      prompt = "#SP_heg__xiejue-choose",
      skill_name = xiejue.name,
      cancelable = false,
    })[1]
    if to then
      H.SwapTwoPlayersDeputy(room, player, to)
    end
  end,
})

xiejue:addEffect("atkrange", {
  correct_func = function (self, from, to)
    if from:getMark("@@heg__xiejue") > 0 then
      return 1
    end
  end,
})


return xiejue